import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/material.dart';

class MyCurvedAnimation extends StatefulWidget {
  const MyCurvedAnimation({Key? key}) : super(key: key);

  @override
  _MyCurvedAnimationState createState() => _MyCurvedAnimationState();
}

class _MyCurvedAnimationState extends State<MyCurvedAnimation> with SingleTickerProviderStateMixin{
  late CurvedAnimation curve;
  late AnimationController controller;

  @override
  initState() {
    super.initState();
    controller = AnimationController(duration: Duration(milliseconds: 1500), vsync: this);
    // 创建一个 CurvedAnimation，监听它的 value
    curve = CurvedAnimation(parent: controller, curve: Curves.easeIn)
    ..addListener(() {
      setState(() {
            if(controller.isCompleted){
              // controller.reset();
              controller.reverse();
            }
            else if(controller.isDismissed){
              controller.forward();
            }
      });
    });
    controller.forward();
  }
  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar('CurvedAnimation'),
      body: Center(
        child: Container(
          margin: EdgeInsets.symmetric(vertical: 10.0),
          // 使用 CurvedAnimation 对象的 value
          height: 300 * curve.value+10,
          width: 300 * curve.value+10,
          child: FlutterLogo(),
        ),
      ),
    );
  }
}
